package com.sgcc.fj.pmos.common.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

/**
 * ViewPager Fragment 适配器
 */
public class HomeTabPagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> mMainFragments;
    private String[] mBottomTabNames;

    public HomeTabPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.mMainFragments = fragments;
    }

    public void setmBottomTabNames(String[] mBottomTabNames) {
        this.mBottomTabNames = mBottomTabNames;
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return POSITION_UNCHANGED;
    }

    @Override
    public Fragment getItem(int position) {
        return mMainFragments.get(position);
    }

    @Override
    public int getCount() {
        return mMainFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mBottomTabNames.length > 0) {
            return mBottomTabNames[position];
        } else {
            return "";
        }
    }

}